// The complied handlebars templates
// =================================
'use strict';

define([
  'handlebars',
  'text!template/trading/coupon-select.hbs',
  'text!template/trading/coupon-item.hbs',
  'text!template/trading/discount-code-select.hbs',
  'text!template/trading/discount-code-item.hbs',
  'text!template/mobile-bind.hbs',
  'text!template/mobile-item.hbs',
  'text!template/email-bind.hbs',
  'text!template/email-item.hbs',
  'text!template/profile/address-edit.hbs',
  'text!template/profile/address-item.hbs',
  'text!template/profile/region-edit.hbs',
  'text!template/profile/region-item.hbs',
  'text!template/profile/bmi-edit.hbs',
  'text!template/profile/bmi-item.hbs',
  'text!template/profile/agent-account.hbs',
  'text!template/profile/agent-withdraw.hbs',
  'text!template/profile/distributor-account.hbs',
  'text!template/profile/distributor-withdraw.hbs',
  'text!template/online-protocol.hbs',
  'text!template/online-year-protocol.hbs',
  'text!template/offline-protocol.hbs',
  'text!template/course/coach-select.hbs',
  'text!template/course/area-select.hbs',
  
], function(Handlebars, 
            couponSelect, couponItem, 
            discountCodeSelect,discountCodeItem,
            mobileBind,   mobileItem,
            emailBind,    emailItem, 
            addressEdit, addressItem, 
            regionEdit,   regionItem,
            bmiEdit,      bmiItem,
            agentAccount, agentWithdraw,
            distributorAccount, distributorWithdraw,
            onlineProtocol,  onlineYearProtocol,
            offlineProtocol,
            coachSelect,     areaSelect) {
  
  Handlebars.registerHelper('currency', function(value, fractionDigits) {
    fractionDigits = fractionDigits || 0
    return (value / 100).toFixed(fractionDigits)
  })

  Handlebars.registerHelper('check', function(oldValue, newValue, trueResult, falseResult) {
    if (oldValue instanceof Array) {

      return oldValue.some(function(item) { return item === newValue }) ? trueResult : (falseResult || '')
    } else {
      return oldValue === newValue ? trueResult : (falseResult || '')
    }
  })
  
  Handlebars.registerHelper('equal', function(value, confirm, options){
    if(value === confirm) {
      return options.fn(this);
    } else {
      return options.inverse(this);
    }
  })
  
  return {
    couponSelectTpl:  Handlebars.compile(couponSelect),
    couponItemTpl:    Handlebars.compile(couponItem),
    discountCodeSelectTpl:  Handlebars.compile(discountCodeSelect),
    discountCodeItemTpl:  Handlebars.compile(discountCodeItem),
    mobileBindTpl:    Handlebars.compile(mobileBind),
    mobileItemTpl:    Handlebars.compile(mobileItem),
    emailBindTpl:     Handlebars.compile(emailBind),
    emailItemTpl:     Handlebars.compile(emailItem),
    addressEditTpl:  Handlebars.compile(addressEdit),
    addressItemTpl:  Handlebars.compile(addressItem),
    regionEditTpl:    Handlebars.compile(regionEdit),
    regionItemTpl:    Handlebars.compile(regionItem),
    bmiEditTpl:       Handlebars.compile(bmiEdit),
    bmiItemTpl:       Handlebars.compile(bmiItem),
    agentAccountTpl:  Handlebars.compile(agentAccount),
    agentWithdrawTpl:  Handlebars.compile(agentWithdraw),
    distributorAccountTpl:  Handlebars.compile(distributorAccount),
    distributorWithdrawTpl:  Handlebars.compile(distributorWithdraw),
    onlineProtocolTpl: Handlebars.compile(onlineProtocol),
    onlineYearProtocolTpl: Handlebars.compile(onlineYearProtocol),
    offlineProtocolTpl: Handlebars.compile(offlineProtocol),
    coachSelectTpl:    Handlebars.compile(coachSelect),
    areaSelectTpl:     Handlebars.compile(areaSelect)
  }
})